<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">添加资质</block>
		</cu-custom>
		
		<view class="cu-list menu animation-scale-down padding" :style="[{animation: 'show 0.5s 1'}]">
			<view class="cu-form-group">
				<view class="title">资质项：</view>
				<textarea auto-height  v-model="content" disabled=false></textarea>
			</view>
		</view>
		<view class="cu-list menu animation-scale-down padding" :style="[{animation: 'show 0.5s 1'}]">
			<view class="cu-form-group">
				<view class="title">分 数：</view>
				<textarea  auto-height  v-model="score" disabled=false></textarea>
			</view>
		</view>
		<view class="cu-list menu animation-scale-down " :style="[{animation: 'show 0.5s 1'}]">
			<uni-card>
				<view class="" style="display: flex;">
					<p class="mytitle">请上传证明文件：</p>
					<button type="primary" size="mini" @tap="chooseFile()">上传文件</button>
				</view>
				<view class="filesitem" v-for="(item,index) in fileList" :key="index":data-url="fileList[index]">
					<view class="" style="width: 100%; height: 30px;">
						<uni-link :href="saveFile(item)" :download="fileName(item)">
							{{fileName(item)}}
						</uni-link>
						<view class="" style="float: right;" @tap.stop="delFile($event)">
							<uni-icons  type="close" size="30" ></uni-icons>
						</view>
					</view>
				</view>
			</uni-card>
		</view>
		
		<view class="padding flex flex-direction">
			<button class="cu-btn bg-blue lg"  @click="onSubmit">提交</button>
		</view>
	</view>
</template>

<script>
	
	 export default {
	 	name: 'addQualification',
		data() {
			return {
				imgUrl: this.$config.staticDomainURL+'/',
				uploadUrl:"/sys/common/upload",
				id: "",
				content: "1111",
				score: "10",
				fileList: ["11_11.pdf","22_11.doc"],
			}
		},
		onLoad() {
			console.log(this.$Route.query);
			if(this.$Route.query.name) {
				this.id = this.$Route.query.id
				this.content = this.$Route.query.name
				this.score = this.$Route.query.score
				this.fileList = []
			}
		},
		methods: {
			saveFile(url) {
				let totalUrl = this.imgUrl+url;
				// console.log(totalUrl)
				return totalUrl
			},
			fileName(e) {
				let temp = e.split(".")
				let suffix = temp.pop()
				temp = temp.join(".")
				temp = temp.split("_")
				temp.pop()
				let name = temp.join("_")
				// console.log(name+"."+suffix)
				return name+"."+suffix
			},
			chooseFile() {
				var that=this;
				uni.chooseFile({
					count: 4, //默认100
					type: 'all',
					success: (res) => {
						console.log("111111",res.tempFilePaths)
						res.tempFilePaths.forEach(item => {
							that.$http.upload(that.$config.apiUrl+that.uploadUrl, {
								filePath: item,
								name: 'file'
							})
							.then((res) => {
								console.log(res)
								that.fileList.push(res.data.message)
								console.log(that.fileList)
							})
							.catch(err => {
								that.$tip.error(err.data.message)
							});
						})
					}
				});
			},
			delFile(e) {
				uni.showModal({
					content: '确定要删除吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							// console.log(1,e.currentTarget.dataset.index)
							this.fileList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			onSubmit() {
				let temp = {
					userId: this.$store.getters.userid,
					scoreItemId: this.id,
					score: this.score.toString(),
					appendix: "",
				}
				if(this.fileList.length) temp.appendix = this.fileList.join(",")
				else temp.appendix = ""
				let znzfEmployeeScoreItemParamList = [temp]
				console.log(znzfEmployeeScoreItemParamList)
				this.$http.post('/base/znzfEmployeeScoreItem/insertEmployeeScoreItemList',{znzfEmployeeScoreItemParamList}).then(res => {
					console.log(res)
					uni.showToast({
						title: "已提交审核",
						icon: 'none'
					})
				})
			},
		},
	 }
</script>

<style>
	.filesitem{
		color: #636363;
		font-size: 16px;
		margin: 2px 0;
	}
</style>

